package com.fedoom.frontend.views;

import com.fedoom.frontend.models.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 * Audio Video view class
 * for changing audio video settings
 * Extends the ModalView class I created
 * @author tony
 *
 */
public class AVView extends ModalView{
	JCheckBox nosoundBox = new JCheckBox();
	JCheckBox nomusicBox = new JCheckBox();
	JCheckBox openglBox = new JCheckBox();
	JComboBox screenResolutionComboBox = new JComboBox(ScreenResolutionOptionsModel.getResolutionModes());
	private int prevResolution = -1;
	/**
	 * @param owner - the jframe that 'contains' this modal dialog
	 */
	public AVView(JFrame owner)
	{
		super(owner);
		setSize(280,200);
		
		this.setCommandFieldNames();
		this.addLabelComponentPair(new JLabel("No Sound?"), nosoundBox);
		this.addLabelComponentPair(new JLabel("Disable Music?"), nomusicBox);
		this.addLabelComponentPair(new JLabel("Use OpenGL?"), openglBox);
		this.addLabelComponentPair(new JLabel("Screen Resolution"), screenResolutionComboBox);
	}
	/**
	 * method for setting names for command fields
	 */
	private void setCommandFieldNames()
	{
		//these names can be used to know what component or field is selected 
		nosoundBox.setName("15");			//changed from "nosound" to "15"
		nomusicBox.setName("16");		//changed from "nomusic" to "16"
		openglBox.setName("7");		//changed from "opengl" to "7"
		this.screenResolutionComboBox.setName("23");		//changed from "screenRes" to 23 (need to check what arg should actually be used)
	}
	/**
	 * constructor - avoid using this constructor
	 */
	public AVView(){
		this(null);
	}

	/**
	 * setVisible was overridden in order to store the existing values of 
	 * the text areas before they are edited in the dialog
	 */
	public void setVisible(boolean b)
	{
		if (b==true)
		{
			prevResolution = this.screenResolutionComboBox.getSelectedIndex();
		}
		super.setVisible(b);
	}

	/**
	 * dispose was overridden to prevent the UI from retaining values when 
	 * a user hits the X to exit a window.
	 * I tested closing windows via OK & via the X.
	 * Only the X calls dispose, so this code won't execute when OK is clicked
	 */
	public void dispose()
	{
		if(this.screenResolutionComboBox!=null && this.prevResolution>=0)
			if (prevResolution!=screenResolutionComboBox.getSelectedIndex())
				screenResolutionComboBox.setSelectedIndex(prevResolution);
		
		super.dispose();
	}
}
